#include "wireless_uart.h"

typedef struct
{
    uint16_t Head;
    uint16_t Tail;
    uint16_t Length;
    uint8_t  Ring_data[wireless_len];
}wireless_t;

wireless_t wireless_Buffer;	//创建一个ringBuffer的缓冲区
uint8_t wireless_rx[1];


void wireless_initBuffer(void)
{
	//初始化相关信息
	wireless_Buffer.Head = 0;
	wireless_Buffer.Tail = 0;
	wireless_Buffer.Length = 0;
	return;
}

void wireless_write1Byte(uint8_t data)
{
	if(wireless_Buffer.Length >= wireless_len) //判断缓冲区是否已满
	{
		return ;
	}
	wireless_Buffer.Ring_data[wireless_Buffer.Tail]=data;
	wireless_Buffer.Tail = (wireless_Buffer.Tail+1)%wireless_len;//防止越界非法访问
	wireless_Buffer.Length++;
	return ;
}

void wireless_delete(uint16_t size)
{
	if(size >= wireless_Buffer.Length)
	{
	    wireless_initBuffer();
	    return;
	}
	for(int i = 0; i < size; i++)
	{
		wireless_Buffer.Head = (wireless_Buffer.Head+1)%wireless_len;//防止越界非法访问
		wireless_Buffer.Length--;
		return;
	}
}

uint8_t wireless_read1Byte(uint16_t position)
{
	uint16_t realPosition = (wireless_Buffer.Head + position) % wireless_len;

	return wireless_Buffer.Ring_data[realPosition];
}




